# @Author: Eric Ito
# @Date: 1/29/2009
# @Name: Project Euler Problem 27

"""
n**2 + an + b where abs(a) < 1000 and  abs(b) < 1000

find the product of the coefficients, a and b, for the
quadratic expression that produces the
maximum number of primes for consecutive values of n,
starting with n=0
"""

from util import isPrime
from util import getPrimes

#PRIMES = getPrimes(1000000)

def main():
    maxPrimes = 0
    A = 0
    B = 0
    n = 0
    counter = 0
    for a in range(-999,1000):
        for b in range(-999,1000):
            prod = (n**2 + (a*n) + b)
            if prod < 0: # primes must be > 0
                continue
            while isPrime(prod):
                counter += 1
                n += 1
                prod = (n**2 + (a*n) + b)
                if prod < 0: # primes must be > 0
                    break
                #print a,b,n,counter
            if counter > maxPrimes:
                maxPrimes = counter
                A = a
                B = b
            counter = 0
            n = 0
    #print "n=",n
    #print "A=",A
    #print "B=",B
    #print "maxPrimes=",maxPrimes
    print A*B


if __name__ == "__main__":
    main()